precision mediump float;

uniform sampler2D vTexture;
varying vec2 aCoordinate;//纹理坐标
varying vec4 glPosition;//变换后的坐标
vec3 rgbArr;

varying vec4 aPos;//变换前的顶点坐标
/*
 *防止RGB大于1或小于0
 */
void modifyColor(vec4 color){
    color.r=max(min(color.r, 1.0), 0.0);
    color.g=max(min(color.g, 1.0), 0.0);
    color.b=max(min(color.b, 1.0), 0.0);
    color.a=max(min(color.a, 1.0), 0.0);
}

void main(){
    //gl_FragColor=vec4(1.0f,1.0f,1.0f,1.0f);
    vec4 nColor=texture2D(vTexture, aCoordinate);//取得每个像素点的RGBA值，对每个像素点进行处理，得到不同滤镜

    //黑白
    //    rgbArr =vec3(0.299f,0.587f,0.114f);
    //    float grey=nColor.r*rgbArr.r+nColor.g*rgbArr.g+nColor.b*rgbArr.b;
    //    gl_FragColor=vec4(grey,grey,grey,nColor.a);


    //冷色调
    //    rgbArr=vec3(0.0f,0.0f,0.4f);
    //    nColor=nColor+vec4(rgbArr,0);
    //    modifyColor(nColor);
    //    gl_FragColor=nColor;


    //暖色调
    //    rgbArr=vec3(0.2f,0.3f,0.0f);
    //    nColor=nColor+vec4(rgbArr,0);
    //    modifyColor(nColor);
    //    gl_FragColor=nColor;


    //放大镜

//        float dis=distance(vec2(glPosition.x,glPosition.y),vec2(0, 0));
//        if(dis<0.5f){
//            nColor=texture2D(vTexture,vec2(aCoordinate.x/2.0+0.25f,aCoordinate.y/2.0+0.25f));
//        }


    //模糊效果  采样了周边12个点的颜色加上当前点的颜色，就是13个了，除以13得到均值

    //半边效果,使用变换前的顶点坐标，判断右边
    if(aPos.x>0.0f){
        rgbArr=vec3(0.006f,0.004f,0.002f);
        nColor+=texture2D(vTexture, vec2(aCoordinate.x-rgbArr.r, aCoordinate.y-rgbArr.r));
        nColor+=texture2D(vTexture, vec2(aCoordinate.x-rgbArr.r, aCoordinate.y+rgbArr.r));
        nColor+=texture2D(vTexture, vec2(aCoordinate.x+rgbArr.r, aCoordinate.y-rgbArr.r));
        nColor+=texture2D(vTexture, vec2(aCoordinate.x+rgbArr.r, aCoordinate.y+rgbArr.r));

        nColor+=texture2D(vTexture, vec2(aCoordinate.x-rgbArr.g, aCoordinate.y-rgbArr.g));
        nColor+=texture2D(vTexture, vec2(aCoordinate.x-rgbArr.g, aCoordinate.y+rgbArr.g));
        nColor+=texture2D(vTexture, vec2(aCoordinate.x+rgbArr.g, aCoordinate.y-rgbArr.g));
        nColor+=texture2D(vTexture, vec2(aCoordinate.x+rgbArr.g, aCoordinate.y+rgbArr.g));

        nColor+=texture2D(vTexture, vec2(aCoordinate.x-rgbArr.b, aCoordinate.y-rgbArr.b));
        nColor+=texture2D(vTexture, vec2(aCoordinate.x-rgbArr.b, aCoordinate.y+rgbArr.b));
        nColor+=texture2D(vTexture, vec2(aCoordinate.x+rgbArr.b, aCoordinate.y-rgbArr.b));
        nColor+=texture2D(vTexture, vec2(aCoordinate.x+rgbArr.b, aCoordinate.y+rgbArr.b));

        nColor/=13.0f;//乘除一定要用.0浮点，否则画不出来
    }



    gl_FragColor=nColor;
}